<template>
  <typeBase>
    <template v-slot:main-left>
      <Institution />
    </template>
    <template v-slot:main-button>
      <mainButton
        @toMainSearch="search"
        @toMainSearchReset="reset"
        :main-button="mainButton"
      />
    </template>
    <template v-slot:search-info>
      <searchMain
        size="mini"
        :label-width="labelWidth"
        ref="searchMain"
        :model="formData"
        :rules="searchRules"
        :itemList="formItemList"
      />
      <el-divider />
    </template>
    <template v-slot:table-main>
      <common-table
        :data="infoList"
        border
        :columns-item="columns"
        :title="infoTitle"
        :loading="false"
        :item-list="itemList"
        @checkbox-change="selectChangeEvent"
      />
    </template>
  </typeBase>
</template>
<script>
import typeBase from "@/components/Layout/typeBase.vue"
import Institution from "@/components/Trees/Institution.vue"
import mainButton from "@/components/CommonButtons/MainButton.vue"
import searchMain from "@/components/CommonForm/index.vue"
import CommonTable from "@/components/CommonTable/index.vue"
// 加载模拟数据
import {
  infoList,
  sexs,
  fileStatusType,
  changeType,
  changeState,
  addressList,
  information,
  isSignType,
  familyInformation,
  complete,
  peopleSigns,
  publicSigns,
  dataProps,
  searchHandle
} from "@/simdata/healthData.js"
export default {
  components: {
    typeBase,
    Institution,
    mainButton,
    searchMain,
    CommonTable
  },
  data() {
    return {
      // 配置标题显示图标颜色
      itemList: [
        {
          label: "高",
          color: "#66FFFF"
        },
        {
          label: "糖",
          color: "#f3daf9"
        },
        {
          label: "精",
          color: "#FFCC99"
        }
      ],
      // 配置常用按钮
      mainButton: [
        {
          label: "档案合并",
          icon: "el-icon-circle-plus-outline",
          type: "primary",
          handle: () => this.addHandle()
        },
        {
          label: "档案状态变更",
          icon: "el-icon-edit-outline",
          type: "success",
          handle: () => {
            console.log("点击了")
          }
        }
      ],
      // 查询表单
      formData: {
        name: "", //
        identityNumber: ""
      },
      // label的宽度
      labelWidth: "auto",
      // 验证
      searchRules: {},
      // 配置search label表单
      formItemList: [
        {
          type: "Input",
          label: "姓名",
          prop: "name",
          span: 8,
          placeholder: ""
        },
        {
          type: "Input",
          label: "身份证号",
          prop: "identityNumber",
          span: 8,
          placeholder: ""
        }
      ],
      // 所有列表数据
      infoTitle: "人员基本信息列表",
      infoList: [],
      // 配置显示的label标签
      columns: [
        { prop: "name", label: "姓名", width: "100" },
        {
          prop: "sex",
          label: "性别",
          width: "68",
          type: "sex",
          option: sexs
        },
        { prop: "age", label: "年龄", width: "80" },
        { prop: "birthdata", label: "出生日期", width: "100" },
        { prop: "identityNumber", label: "身份证号", width: "180" },
        { prop: "phonenumber", label: "本人电话号码", width: "150" },
        { prop: "linkName", label: "联系人姓名", width: "100" },
        { prop: "linkNumber", label: "联系人电话", width: "150" },
        { prop: "nowAddress", label: "现住地址", width: "150" },
        {
          prop: "isSign",
          label: "是否签约",
          width: "80",
          type: "isSign",
          option: isSignType
        },
        { prop: "responsibleDoctor", label: "责任医生", width: "100" },
        {
          prop: "isHome",
          label: "家庭信息",
          width: "80",
          type: "isHome",
          option: familyInformation
        },
        { prop: "creatDoctor", label: "建档医生", width: "100" },
        { prop: "createDate", label: "建档日期", width: "100" },
        { prop: "myNumber", label: "个人健康档案号", width: "150" },
        { prop: "number", label: "家庭档案号", width: "150" },
        {
          prop: "isComplete",
          label: "信息是否完整",
          width: "120",
          type: "isComplete",
          option: complete
        },
        {
          prop: "isLibrary",
          label: "人口库标记",
          width: "100",
          type: "isLibrary",
          option: peopleSigns
        },
        {
          prop: "isPublic",
          label: "公安标记",
          width: "80",
          type: "isPublic",
          option: publicSigns
        }
      ]
    }
  },
  methods: {
    // 点击新增按钮
    addHandle() {
      console.log("点击了")
    },
    // 切换常用地址
    handleChange() {
      console.log("点击了")
    },
    // 点击搜索按钮
    search(formName) {
      this.$refs.searchMain.$refs[formName].validate(valid => {
        if (valid) {
          console.log(this.formData)

          // 调用接口
          this.callbackComponent()
        } else {
          console.log("error submit!!")
          return false
        }
      })
    },
    // 点击重置按钮
    reset(formName) {
      this.$refs.searchMain.$refs[formName].resetFields()
      // console.log(this.formData)
    },
    // 点击搜索后，请求后台接口了
    callbackComponent() {
      console.log("调接口")
    },
    // 家庭基本信息复选框选中
    selectChangeEvent({ checked, records }) {}
  }
}
</script>
<style lang="scss" scoped>
/deep/ .common-table {
  margin-right: 0;
}
/deep/ .table-item {
  margin-right: 0 !important;
}
</style>
